clear all;close all

L = 100000;
N = 2;
no_w = 20;
w = linspace(1,5,no_w);
P_q = (1.2).^([1:N]'-1);
P_q_1 = 1;
P_q_2 = 1.5;

no_Delta = 3;


Delta = linspace(0,1,no_Delta)';
q_1 = ones(no_Delta,1);
q_2 = q_1 + Delta;

sh_q_1 = 0.7;
a_q_1 = zeros(no_Delta,1);
a_q_2 = log((1/sh_q_1 - 1)*(w(1,1)/P_q_1).^(q_1)) - log((w(1,1)/P_q_2).^(q_2));

w_grid = repmat(w,no_Delta,1);
q_1_grid = repmat(q_1,1,no_w);
q_2_grid = repmat(q_2,1,no_w);
a_q_1_grid = repmat(a_q_1,1,no_w);
a_q_2_grid = repmat(a_q_2,1,no_w);
P_q_1_grid = repmat(P_q_1,no_Delta,no_w);
P_q_2_grid = repmat(P_q_2,no_Delta,no_w);

rho_q_1 = exp(a_q_1_grid + q_1_grid.*log(w_grid./P_q_1_grid))./(exp(a_q_1_grid + q_1_grid.*log(w_grid./P_q_1_grid)) + exp(a_q_2_grid + q_2_grid.*log(w_grid./P_q_2_grid)));
rho_q_2 = exp(a_q_2_grid + q_2_grid.*log(w_grid./P_q_2_grid))./(exp(a_q_1_grid + q_1_grid.*log(w_grid./P_q_1_grid)) + exp(a_q_2_grid + q_2_grid.*log(w_grid./P_q_2_grid)));

pe_eg = figure(1);
plot(w_grid(1,:)',rho_q_2(1,:)','b-','LineWidth',1.5);
hold on
plot(w_grid(2,:)',rho_q_2(2,:)','g--','LineWidth',2);
plot(w_grid(3,:)',rho_q_2(3,:)','r:','LineWidth',5);
ylabel('\rho(q_2|w)');
handle = get(gca, 'ylabel');
set(handle, 'FontWeight', 'Bold','FontSize',15,'FontName','TimesNewRoman');
xlabel('Wage')
handle = get(gca, 'xlabel');
set(handle, 'FontWeight', 'Bold','FontSize',15,'FontName','TimesNewRoman');
set(gca,'YLim',[1 - sh_q_1 - .05, max(max(rho_q_2)) + 0.02 ]);
handle = legend;
set(handle,'interpreter','latex');
l1 = legend('\Delta = 0','\Delta = 0.5','\Delta = 1');
set(l1,'FontSize',15)
set(l1,'Location','Best');
% set(gcf, 'PaperPosition', [0 0 5 5]); %Position plot at left hand corner with width 5 and height 5.
% set(gcf, 'PaperSize', [5 5]); %Set the paper to have width 5 and height 5.
% ti = get(gca,'TightInset')
% set(gca,'Position',[ti(1) ti(2) 1-ti(3)-ti(1) 1-ti(4)-ti(2)]);
% set(gca,'units','centimeters')
% pos = get(gca,'Position');
% ti = get(gca,'TightInset');
% set(gcf, 'PaperUnits','centimeters');
% set(gcf, 'PaperSize', [pos(3)+ti(1)+ti(3) pos(4)+ti(2)+ti(4)]);
% set(gcf, 'PaperPositionMode', 'manual');
% set(gcf, 'PaperPosition',[0 0 pos(3)+ti(1)+ti(3) pos(4)+ti(2)+ti(4)]);
% saveas(pe_eg,'C:\Users\Siddharth\Documents\phd\financial frictions &
% social mobility\presentations\JM Practice
% Sept\results\pe_non_homotheticity.png','png')

current_folder = cd;

print(pe_eg,'-depsc2',strcat(current_folder,'\results\pe_non_homotheticity.eps'));